<?php

namespace App\Library\Requests\Coupon;

use App\Library\Requests\Base\BaseDTORequest;
use App\Library\Rules\MediaImgRule;
use Illuminate\Validation\Rule;

class CouponAddRequest extends BaseDTORequest
{
    public function rules(): array
    {
        return [
            'title' => 'required|string|max:255',
            'fileId' => ['nullable', new MediaImgRule],
            'couponType' => 'required|integer|in:0,1',
            'amount' => [Rule::requiredIf($this->couponType == 0), 'required_unless:couponType, 0', 'numeric', 'min:0.01', 'regex:' . __('com.priceReg')],
            'discount' => [Rule::requiredIf($this->couponType == 1), 'integer', 'between:10,99', 'required_without:amount'],
            'fullDec' => ['required', 'numeric', 'min:0.01', 'regex:' . __('com.priceReg')],
            'expType' => 'required|boolean',
            'expStartAt' => [Rule::requiredIf($this->expType == 1), 'date', 'date_format:Y-m-d', 'after_or_equal:' . now()->toDateString()],
            'expEndAt' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:expStartAt', 'required_with:expStartAt'],
            'quantity' => 'required|integer|min:1',
            'getCount' => 'required|integer|min:1|lte:quantity',
            'useRange' => 'required|integer|between:0,5',
            'sendWay' => 'required|integer|between:0,2',
            'point' => [Rule::requiredIf($this->sendWay === 1), 'numeric', 'min:0', 'regex:' . __('com.amount')],
            'businessType' => 'required|integer|between:0,3',
            'drawerId' => [Rule::requiredIf($this->useRange == 2), 'integer', 'min:1'],
            'activityId' => [Rule::requiredIf($this->useRange == 3), 'integer', 'min:1'],
            'sendStartAt' => 'required|date|date_format:Y-m-d|after_or_equal:' . now()->toDateString(),
            'sendEndAt' => 'required_with:sendStartAt|date|date_format:Y-m-d|after_or_equal:sendStartAt',
            'system' => 'required|boolean',
            'sort' => 'nullable|min:0'
        ];
    }
}
